package org.example.tree;

/**
 * @author liyishan
 * @date 2024/2/23 09:47
 * @apiNote
 */

public class Test00111MinDepth {

    public int minDepth(TreeNode root) {
        if (root == null) {
            return 0;
        }
        if(root.left == null && root.right == null){
            return 1;
        }
        int minDepth = Integer.MAX_VALUE;
        if(root.left != null){
            minDepth = Math.min(minDepth(root.left), minDepth);
        }
        if(root.right != null){
            minDepth = Math.min(minDepth(root.right), minDepth);
        }
        return minDepth + 1;
    }
}
